<?php
defined('IN_IXDCW') or exit('Access Denied');
function ad_name($ad = array()) {
	if($ad['typeid'] > 5) {
		if($ad['key_word']) {
			return 'ad_t'.$ad['typeid'].'_m'.$ad['key_moduleid'].'_k'.urlencode($ad['key_word']).'_'.$ad['areaid'].'.htm';
		} else if($ad['key_catid']) {
			return 'ad_t'.$ad['typeid'].'_m'.$ad['key_moduleid'].'_c'.$ad['key_catid'].'_'.$ad['areaid'].'.htm';
		} else {
			return 'ad_t'.$ad['typeid'].'_m'.$ad['key_moduleid'].'_'.$ad['areaid'].'.htm';
		}
	} else {
		return 'ad_'.$ad['pid'].'_'.$ad['areaid'].'.htm';
	}
}


function xd_ext_ad_cats(){
	$types = get_type('ad_place');
	$arr   = array();
	foreach($types as $v) {
		if (strpos($v['typename'], '分站') !== false) {
			$arr['sub'][] = $v;
		} else {
			$arr['all'][] = $v;
		}
	}
	return $arr;
}

function xd_ext_ad_page_cats() {
	global $db;
	$sql = "select itemid, title, linkurl from {$db->getPre()}webpage where item='ads' order by listorder asc";
	$cats = $db->getAll($sql);
	$arr = array();
	foreach($cats as $v) {
		if (trim($v['title']) == '广告加盟') {
			continue;
		}
		if (strpos($v['title'], '分站') !== false) {
			$arr['sub'][] = $v;
		} else {
			$arr['all'][] = $v;
		}
	}
	return $arr;
}

/**
 * 存储扩展函数中独用的函数库
 * Class FunExtendIds
 */
class FunExtendIds
{
	/**
	 * 生成子链接
	 * @param        $catid
	 * @param        $types
	 * @param        $field
	 * @param        $name
	 * @param string $cutter
	 * @return string
	 */
	public static function subLink($catid, $types, $field, $name, $cutter = '&nbsp;&gt;&nbsp;')
	{
		$contents = array();
		if ($catid == 0) {
			$contents[] = $name;
		} else {
			$contents[] = '<a href="'.xd_dynamic_url($field, 0, $GLOBALS['ids_buildbase']).'">'.$name.'</a>';
			foreach($types as $type) {
				if ($catid == $type['typeid']) {
					$contents[] = $type['typename'];
				}
			}
		}
		return implode($cutter, $contents);
	}
}


